package cn.tedu.orderservice.controller;

import cn.tedu.charging.common.response.JsonResult;
import cn.tedu.orderservice.pojo.dto.OrderParam;
import cn.tedu.orderservice.pojo.vo.OrderDetailVO;
import cn.tedu.orderservice.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单接口")
@Slf4j
@RestController
@RequestMapping("/v1/order/")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult createOrder(@Validated  @RequestBody OrderParam orderParam){
        log.debug("C1-创建订单:{}",orderParam);
        String orderNum=orderService.create(orderParam);
        log.debug("C1-返回数据:{}",orderNum);
        return JsonResult.success(orderNum);
    }

    @ApiOperation("停止充电")
    @PostMapping("normalstop/{orderNo}")
    public JsonResult<OrderDetailVO> normalStopCharging(@PathVariable String orderNo){
        log.debug("C2-用户手动停止:{}",orderNo);
        OrderDetailVO orderDetailVO=orderService.normalStopCharging(orderNo);
        return JsonResult.success(orderDetailVO);
    }
}
